<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>应用服务器管理</title>
<block th:replace="commonBase"></block>   
</head>
<body>
    <!-- 菜单栏开始 -->
    <div style="width:100%;">
		<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
			<table style="width:100%;">
				<tr>
	                <td style="width:100%;" > 
	                  	 <a sec:authorize="hasAuthority('server:add')"  class="mini-button"  plain="true"  iconCls="icon-addnew" onclick="add">添加</a>
	                 	 <a sec:authorize="hasAuthority('server:update')" class="mini-button"  plain="true"  iconCls="icon-edit"   onclick="edit">编辑</a>
	                 	 <a sec:authorize="hasAuthority('server:delete')" class="mini-button"  plain="true"  iconCls="icon-remove" onclick="remove">删除</a> 
	                 </td>	
					 <td style="white-space:nowrap;">
						 <input id="searchKey" class="mini-textbox" emptyText="请输入名称或编码" style="width:150px;" onenter="search"/>
						 <a class="mini-button" onclick="search()" iconCls="icon-search">查询</a>
				     </td> 
				</tr>
			</table>
		</div>
	</div>
	<!-- 菜单栏结束 -->
	
	<!-- 列表展示开始 -->
	<div class="mini-fit">
		<div id="grid1" class="mini-datagrid" style="width:100%;height:100%;" 
			 allowCellSelect="true" multiSelect="true" allowAlternating="true" sortField="server_code,server_name" sortOrder="desc" idField="id" pageSize="20" sizeList="[10,20,50,100]"
			 th:attr="url=@{/server/pagelist}"  >
			<div property="columns">
				<!-- <div type="indexcolumn"></div> -->
				<div type="checkcolumn"></div>
				<div field="serverCode"  sortField="server_code" width="100" allowSort="true" headerAlign="center" align="left">应用上下文</div>
				<div field="serverName" sortField="server_name" width="100" allowSort="true" headerAlign="center" align="center">子系统服务名称</div>
				<div field="serverIp" sortField="server_ip" width="100" allowSort="true" headerAlign="center" align="center">子系统服务地址</div>
				<div field="serverPort" width="100" headerAlign="center" align="right">子系统服务端口</div> 
			<!-- 	<div field="isMain" width="100"  renderer="onOpenIsmainName">是否是主服务器</div> -->
				<!-- <div field="isEnable" width="100"  renderer="onOpenURenderer">是否启用</div> -->
				<div field="remark" width="100" headerAlign="center" align="left">备注</div>   
			</div>
		</div>
	</div>
	<!-- 列表展示结束 -->
</body>
<script th:inline="javascript" type="text/javascript">
 /*<![CDATA[*/
	var orgNameList = null;
	var grid =  null;//表格对象
	$(function(){
		  mini.parse();
		  grid = mini.get("grid1");
		  search();
	});
	
	/***查询***/
	function search() {
		var  searchKey= mini.get("searchKey").getValue();
		if(searchKey!=""){
			grid.load({"searchPhrase":searchKey});
		}else{
			grid.load();
		}
	}
	
	function add(){
		 mini.open({
	        url:basePath+"server/edit",
	        title: "新增应用服务器", iconCls:'icon-addnew', width: 600, height: 350,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { action:"new"};
	            iframe.contentWindow.setData(data);
	        },
	        ondestroy: function (action) {
				if (action != "close" && action != "cancle"){
	        		  search();
				}
	        }
	    });
	
	}
	
	function edit(){
		var rows = grid.getSelecteds();
		if(rows.length>1){
			mini.alert("只能选择一条记录!");
			return;
		}
		var row = grid.getSelected();
	    if (row) {
				 mini.open({
			        url:basePath+"server/edit",     
			        title: "编辑应用服务器", iconCls:'icon-edit', width: 528, height: 360,
			        onload: function () {
			             var iframe = this.getIFrameEl();
			            var data = {action:"edit",fwPlServer:row};
			            iframe.contentWindow.setData(data);
			        },
			        ondestroy: function (action) {
						if (action != "close" && action != "cancle"){
			        		  search();
						}
			        }
			    });
	    }
	
	}
	
	// 删除
	function remove(){
		var rows = grid.getSelecteds();
		if (rows.length > 0 ){
			//mini.confirm("确定删除选中记录？","提示!",function(e){
				//if (e == "ok"){
					var rowArray = [];// 当前删除行的数组
					var rowIndex = 0;
				    if (rows.length > 0) {
				        // 当前选中列数据循环检测
				  		$.each(rows,function (idx,rowsObj){
				  			var nid = rowsObj.id;
							rowArray[rowIndex++] = nid;
				  		});
				       if (rowArray.length != 0){
				       		var ids = rowArray.toString();
				       		 $.ajax({
				       			url:basePath+"server/delete?ids="+ids,
				       			type:"delete",
				       			data:null,
				       			success:function(successData){
				       	        	var message = mini.decode(successData);
						        	if(message.type == '200'){
						            	showMsg("应用服务器删除成功","success",800,"center","center");
						        	    search();
						        	}else{
						        		showMsg("应用服务器删除失败","warning",800,"center","center");
						        	}
				       			},
				       			error:function(errorData){
		        	 				showMsg("应用服务器删除错误","danger",800,"center","center");
				       			}
				       		}); 
				       }
				    }
			//	}
			//});
		}else{
			mini.alert("请选中一条记录!");
		}
	}
/*]]>*/
</script>
</html>